﻿#include "cocos2d.h"
#include "CCEGLView.h"
#include "AppDelegate.h"
#include "SimpleAudioEngine.h"

//#include "GameScene.h"
//#include "GameManager.h"
#include "YHGameSceneManager.h"
#include "YHGameLoginScene.h"
#include "YHGameMainScene.h"
#include "YHGameLayerLogin.h"
#include "YHGameLayerLoading.h"
#include "YHGameLayerMain.h"
#include "YHGameLayerOver.h"
#include "YHGameLayerSetting.h"
#include "YHFileManager.h"
#include "YHGameLayerMap.h"
#include "YHGameLayerFight.h"

using namespace CocosDenshion;

USING_NS_CC;

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
    SimpleAudioEngine::end();
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
//     CCDirector *pDirector = CCDirector::sharedDirector();
//     pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());

	CCDirector *pDirector = CCDirector::sharedDirector();
	pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

    // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
//     pDirector->enableRetinaDisplay(true);

    // turn on display FPS
    //pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    //CCScene *pScene = HelloWorld::scene();

    // run

	//CCScene *pScene = GameScene::node();	// HelloWorld::scene();

    // run
	//pDirector->runWithScene(pScene);

//	GameManager::sharedGameManager()->runSceneWithId(GameManager::SCENE_MENU);
	//主程序入口
 //  YHGameLoginScene* loginScene = (YHGameLoginScene*)
 //       YHGameSceneManager::sharedGameSceneManager()->pushSceneWithId("YHGameLoginScene", GAME_SCENE_LOGIN);
    YHGameMainScene* mainScene = (YHGameMainScene*)
          YHGameSceneManager::sharedGameSceneManager()->pushSceneWithId("YHGameMainScene", GAME_SCENE_MAIN);
    
    /*YHGameLayerSetting* layer = (YHGameLayerSetting*)
        YHGameSceneManager::sharedGameSceneManager()->pushLayerWithId("YHGameLayerSetting", GAME_LAYER_SETTING);
    layer->init();*/
    
   // YHGameLayerLogin* layer = (YHGameLayerLogin*) YHGameSceneManager::sharedGameSceneManager()->pushLayerWithId("YHGameLayerLogin", GAME_LAYER_LOGIN);
    //layer->init();
    //YHGameLayerMain * layer = (YHGameLayerMain*) YHGameSceneManager::sharedGameSceneManager()->pushLayerWithId("YHGameLayerMain", GAME_LAYER_MAIN);
    // layer->init();
    //YHGameLayerMap* layer = (YHGameLayerMap*) YHGameSceneManager::sharedGameSceneManager()->pushLayer("YHGameLayerMap");
    //layer->init();

    YHGameLayerLoading * layer = (YHGameLayerLoading*) YHGameSceneManager::sharedGameSceneManager()->pushLayerWithId("YHGameLayerLoading", GAME_LAYER_LOADING);
     layer->init();
    //YHGameLayerMap* layer = (YHGameLayerMap*) YHGameSceneManager::sharedGameSceneManager()->pushLayer("YHGameLayerMap");
    //layer->init();
    
    //YHGameLayerFight* layer = YHGameLayerFight::sharedGameLayerFight();
    
     //YHGameSceneManager::sharedGameSceneManager()->pushLayer(layer);
  //  YHFileManger* fileManger = YHFileManger::sharedInstance();

    
    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->pause();

    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->resume();

    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
